package com.zhiyou100.servlet.management.student;

import com.zhiyou100.entity.Student;
import com.zhiyou100.service.StudentService;
import com.zhiyou100.util.parameter.GetParameters;
import org.apache.log4j.Logger;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description TODO 更新一个
 * @packageName ${PACKAGE_NAME}
 * @ClassName ${NAME}
 * @Author yang
 * @Date 8/13/20 20:19
 * @Version V1.0
 */
@WebServlet(name = "UpdateOne", urlPatterns = "/management/student/UpdateOne")
public class UpdateOne extends HttpServlet {
    final Logger logger = Logger.getLogger(this.getClass());

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 从参数列表获取一个 student
        final Student student = GetParameters.getParameters(request, Student.class);
        logger.info(student);
        try (StudentService studentService = new StudentService()) {
            studentService.updateOne(student);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
